﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Home_Task_22_11_2014
{
    class Program
    {
        static void Main(string[] args)
        {
            int len = 5;
            int[] array = new int[len];
            Console.WriteLine("Plese input array elements: ");
            for (int i = 0; i < len; i++)
            {
                array[i] = ReadIntFromConsole();
            }
            Console.WriteLine("Reversed array: ");
            int[] revArray = arrayReverse(array);
            for (int i = 0; i < revArray.Length; i++)
            {
                Console.Write("{0} ", revArray[i]);
            }
            Console.WriteLine("\nInput element that should be removed: ");
            int element = ReadIntFromConsole();
            array = RemoveElements(array, element);
            Console.WriteLine("\nNew array: ");
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write("{0} ", array[i]);
            }
        }


        static int[] RemoveElements(int[] array, int element)
        {
            int ln = array.Length;
            for (int i = 0; i < ln; i++)
            {
                if (array[i] == element)
                {
                    for (int j = i; j < ln - 1; j++)
                    {
                        array[j] = array[j + 1];
                    }
                    ln--;
                    i--;
                }
            }
            int[] resultArray = new int[ln];
            for (int i = 0; i < ln; i++)
            {
                resultArray[i] = array[i];
            }
            return resultArray;
        }

        static int[] arrayReverse(int[] array)
        {
            int j = 0;
            int[] resultArray = new int[array.Length];
            for(int i = array.Length-1; i>=0; i--)
            {
                resultArray[j] = array[i];
                j++;
            }
            return resultArray;
        }

        static int ReadIntFromConsole()
        {
            int number = 0;
            bool flag = false;
            while (!flag)
            {
                try
                {
                    number = Int32.Parse(Console.ReadLine());
                    flag = true;
                }
                catch
                {
                    flag = false;
                }
            }
            return number;
        }
    }
}
